mui.init({
	gestureConfig: {
		longtap: true, //默认为false
	}
});

mui.init({
	pullRefresh: {
		container: '#offCanvasContentScroll',
		up: {
			contentrefresh: '正在加载...',
			callback: pullupRefresh
		}
	},
	gestureConfig: {
		longtap: true, //默认为false
	}
});
var bookshelf = new Vue({
	el: '.line',
	data: {
		books: []
	},
	updated: function() {
		$(".bookdata").on("tap", function() {
			common.open("../bookdetails/details.html", "", $(this).attr("bookuid"))
		})
		$(".bookdata").on("longtap", function() {
			heid()
			$(this).find(".remove").css("display", "block")
			$(this).find(".remove_text").css("display", "block")
		})
		$(".remove_text").on("tap", function(e) {
			var self = $(this)
			common.ajax("student/myShelf/delete", {
				uid: common.uid,
				token: common.token,
				bookUid: self.parents(".bookdata").attr("bookuid")
			}, function(data) {
				if(data.code == 200) {
					heid()
					self.parents(".bookdata").remove()
					mui.toast("成功删除")
					if($(".bookdata").length == 0) {
						$(".empty").css("display", "block")
						$("#offCanvasContentScroll").css("display", "none")
					}
					var go = plus.webview.getWebviewById("../stacks/Recommended.html")
					mui.fire(go, "refresh")
				} else {
					mui.toast(data.message)
				}
			})
			e.stopPropagation()
		})
		$(".remove").on("tap", function(e) {
			heid()
			e.stopPropagation()
		})
		$("body").on("tap", function() {
			heid()
		})
	}
});

$(".empty").height($(window).height() - 44)

function heid() {
	$(".remove").css("display", "none")
	$(".remove_text").css("display", "none")
}

var pageSize = 1

/**
 * 上拉加载具体业务实现
 */
function pullupRefresh() {
	var self = this
	common.ajax("student/myShelf/queryMyShelf", {
		uid: common.uid,
		token: common.token,
		page: pageSize++,
		pageSize: "1000"
	}, function(data) {
		//		console.log(JSON.stringify(data.data.list))
		//		mui('#offCanvasContentScroll').pullRefresh().refresh(true);
		if(data.code == 200) {
			$("body").show()
			mui('#offCanvasContentScroll').pullRefresh().refresh(true);
			if(data.data.list.length == 0) {
				$(".empty").css("display", "block")
				$("#offCanvasContentScroll").css("display", "none")
			} else {
				$(".empty").css("display", "none")
				$("#offCanvasContentScroll").css("display", "block")
			}
			if(!data.data.hasNextPage) {
				mui('#offCanvasContentScroll').pullRefresh().endPullupToRefresh(true)
			} else {
				mui('#offCanvasContentScroll').pullRefresh().endPullupToRefresh()
			}
			for(var i = 0; i < data.data.list.length; i++) {
				bookshelf.books.push(data.data.list[i])
			}
			bookshelf.$nextTick(function() {
				$(".book").height($(".book").find("img").width() * (16 / 10))
			})
		} else {
			mui.toast(data.message)
		}
	}, "get")
}

$(".seach_val").on("focus", function() {
	common.open("../teachstudy/seach.html", "../teachstudy/seach.html", "")
	$(this).blur();
})

window.addEventListener("index", function() {
	location.reload();
})

setTimeout(function() {
	window.location.reload;
	shauxin()
}, 300)

function shauxin() {
	if(mui.os.plus) {
		mui.plusReady(function() {
			setTimeout(function() {
				window.location.reload;
				mui('#offCanvasContentScroll').pullRefresh().pullupLoading();
			}, 300);

		});
	} else {
		mui.ready(function() {
			window.location.reload;
			mui('#offCanvasContentScroll').pullRefresh().pullupLoading();
		});
	}

}